<template>
  <div class="ui-page ui-page__scroll lesson-reply">
    <div class="reply-header">
      <span></span>
      <div class="reply-submit" @click="handleClickSubmitReview()">提交</div>
    </div>
    <textarea class="reply-textarea" :placeholder="`回复` + nickName + ':'" v-model="content"></textarea>
  </div>
</template>

<script>
import { addLessonComment } from "api/order/lession.js";
export default {
  name: "LessonReplyPage",
  data() {
    return {
      content: "",
      replyId: "",
      lessonId: "",
      parentId: "",
      commentId: "",
      nickName: ""
    };
  },
  onLoad() {
    const curUrl = this.$url();
    // this.lessonId = curUrl.query.id || "353";
    this.replyId = this.$route.query.replyId;
    this.lessonId = this.$route.query.lessonId;
    this.parentId = this.$route.query.parentId;
    this.commentId = this.$route.query.commentId;
    this.nickName = this.$route.query.nickName;
  },
  created() {},
  mounted() {},
  methods: {
    handleClickSubmitReview() {
      var self = this;
      if (this.content.trim() == "") {
        this.$toast("内容不能为空");
        return;
      }

      if (this.content.trim().length >= 200) {
        this.$toast("内容只能在200字以内");
        return;
      }
      this.$toast.loading({
        message: "加载中...",
        forbidClick: true,
        overlay: true
      });
      var params = {
        replyId: this.replyId,
        commentId: this.commentId,
        lessonId: this.lessonId,
        parentId: this.parentId,
        content: this.content
      };
      addLessonComment(params).then(({ respCode, respMsg, result }) => {
        this.$toast.clear(true);
        if (respCode !== "0") {
          this.$toast.fail(respMsg);
        }
        this.$toast.success("回复成功");

        this.$router.push({
          path: `/lession/detail`,
          query: {
            id: this.lessonId,
            sid: this.$route.query.sid
          }
        });
      });
    }
  }
};
</script>

<style lang="scss" src="./index.scss"></style>
